<?xml version='1.0' encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <link href="cpip.css" rel="stylesheet" type="text/css" />
    <title>File: /Users/paulross/dev/linux/linux-3.13/include/linux/ktime.h</title>
  </head>
  <body>
    <h1>File: /Users/paulross/dev/linux/linux-3.13/include/linux/ktime.h</h1>
    <p>Green shading in the line number column
means the source is part of the translation unit, red means it is conditionally excluded.
Highlighted line numbers link to the translation unit page. Highlighted macros link to
the macro page.</p>
    <pre><a name="1" /><span class="True">       1:</span> <span class="k">/*</span>
<a name="2" /><span class="True">       2:</span> <span class="k"> *  include/linux/ktime.h</span>
<a name="3" /><span class="True">       3:</span> <span class="k"> *</span>
<a name="4" /><span class="True">       4:</span> <span class="k"> *  ktime_t - nanosecond-resolution time format.</span>
<a name="5" /><span class="True">       5:</span> <span class="k"> *</span>
<a name="6" /><span class="True">       6:</span> <span class="k"> *   Copyright(C) 2005, Thomas Gleixner &lt;tglx@linutronix.de&gt;</span>
<a name="7" /><span class="True">       7:</span> <span class="k"> *   Copyright(C) 2005, Red Hat, Inc., Ingo Molnar</span>
<a name="8" /><span class="True">       8:</span> <span class="k"> *</span>
<a name="9" /><span class="True">       9:</span> <span class="k"> *  data type definitions, declarations, prototypes and macros.</span>
<a name="10" /><span class="True">      10:</span> <span class="k"> *</span>
<a name="11" /><span class="True">      11:</span> <span class="k"> *  Started by: Thomas Gleixner and Ingo Molnar</span>
<a name="12" /><span class="True">      12:</span> <span class="k"> *</span>
<a name="13" /><span class="True">      13:</span> <span class="k"> *  Credits:</span>
<a name="14" /><span class="True">      14:</span> <span class="k"> *</span>
<a name="15" /><span class="True">      15:</span> <span class="k"> *      Roman Zippel provided the ideas and primary code snippets of</span>
<a name="16" /><span class="True">      16:</span> <span class="k"> *      the ktime_t union and further simplifications of the original</span>
<a name="17" /><span class="True">      17:</span> <span class="k"> *      code.</span>
<a name="18" /><span class="True">      18:</span> <span class="k"> *</span>
<a name="19" /><span class="True">      19:</span> <span class="k"> *  For licencing details see kernel-base/COPYING</span>
<a name="20" /><span class="True">      20:</span> <span class="k"> */</span>
<a name="21" /><span class="Maybe">      21:</span> <span class="f">#</span><span class="n">ifndef</span> <a href="cpu.c_macros_ref.html#_X0xJTlVYX0tUSU1FX0hfMA__"><span class="b">_LINUX_KTIME_H</span></a>
<a name="22" /><span class="Maybe">      22:</span> <span class="f">#</span><span class="n">define</span> <a href="cpu.c_macros_ref.html#_X0xJTlVYX0tUSU1FX0hfMA__"><span class="b">_LINUX_KTIME_H</span></a>
<a name="23" /><span class="Maybe">      23:</span> 
<a name="24" /><span class="Maybe">      24:</span> <span class="f">#</span><span class="n">include</span> <span class="f">&lt;</span><span class="b">linux</span><span class="f">/</span><span class="b">time</span><span class="f">.</span><span class="b">h</span><span class="f">&gt;</span>
<a name="25" /><span class="Maybe">      25:</span> <span class="f">#</span><span class="n">include</span> <span class="f">&lt;</span><span class="b">linux</span><span class="f">/</span><span class="b">jiffies</span><span class="f">.</span><span class="b">h</span><span class="f">&gt;</span>
<a name="26" /><span class="Maybe">      26:</span> 
<a name="27" /><span class="Maybe">      27:</span> <span class="k">/*</span>
<a name="28" /><span class="Maybe">      28:</span> <span class="k"> * ktime_t:</span>
<a name="29" /><span class="Maybe">      29:</span> <span class="k"> *</span>
<a name="30" /><span class="Maybe">      30:</span> <span class="k"> * On 64-bit CPUs a single 64-bit variable is used to store the hrtimers</span>
<a name="31" /><span class="Maybe">      31:</span> <span class="k"> * internal representation of time values in scalar nanoseconds. The</span>
<a name="32" /><span class="Maybe">      32:</span> <span class="k"> * design plays out best on 64-bit CPUs, where most conversions are</span>
<a name="33" /><span class="Maybe">      33:</span> <span class="k"> * NOPs and most arithmetic ktime_t operations are plain arithmetic</span>
<a name="34" /><span class="Maybe">      34:</span> <span class="k"> * operations.</span>
<a name="35" /><span class="Maybe">      35:</span> <span class="k"> *</span>
<a name="36" /><span class="Maybe">      36:</span> <span class="k"> * On 32-bit CPUs an optimized representation of the timespec structure</span>
<a name="37" /><span class="Maybe">      37:</span> <span class="k"> * is used to avoid expensive conversions from and to timespecs. The</span>
<a name="38" /><span class="Maybe">      38:</span> <span class="k"> * endian-aware order of the tv struct members is chosen to allow</span>
<a name="39" /><span class="Maybe">      39:</span> <span class="k"> * mathematical operations on the tv64 member of the union too, which</span>
<a name="40" /><span class="Maybe">      40:</span> <span class="k"> * for certain operations produces better code.</span>
<a name="41" /><span class="Maybe">      41:</span> <span class="k"> *</span>
<a name="42" /><span class="Maybe">      42:</span> <span class="k"> * For architectures with efficient support for 64/32-bit conversions the</span>
<a name="43" /><span class="Maybe">      43:</span> <span class="k"> * plain scalar nanosecond based representation can be selected by the</span>
<a name="44" /><span class="Maybe">      44:</span> <span class="k"> * config switch CONFIG_KTIME_SCALAR.</span>
<a name="45" /><span class="Maybe">      45:</span> <span class="k"> */</span>
<a name="46" /><span class="Maybe">      46:</span> <span class="m">union</span> <span class="b">ktime</span> <span class="f">{</span>
<a name="47" /><span class="Maybe">      47:</span>     <span class="b">s64</span>    <span class="b">tv64</span><span class="f">;</span>
<a name="48" /><span class="False">      48:</span> <span class="f">#</span><span class="n">if</span> <a href="cpu.c_macros_ref.html#_QklUU19QRVJfTE9OR18w"><span class="b">BITS_PER_LONG</span></a> <span class="f">!=</span> <span class="c">64</span> <span class="f">&amp;&amp;</span> <span class="f">!</span><span class="b">defined</span><span class="f">(</span><span class="b">CONFIG_KTIME_SCALAR</span><span class="f">)</span>
<a name="49" /><span class="False">      49:</span>     <span class="m">struct</span> <span class="f">{</span>
<a name="50" /><span class="False">      50:</span> <span class="f">#</span> <span class="n">ifdef</span> <span class="b">__BIG_ENDIAN</span>
<a name="51" /><span class="False">      51:</span>     <span class="b">s32</span>    <span class="b">sec</span><span class="f">,</span> <span class="b">nsec</span><span class="f">;</span>
<a name="52" /><span class="False">      52:</span> <span class="f">#</span> <span class="n">else</span>
<a name="53" /><span class="False">      53:</span>     <span class="b">s32</span>    <span class="b">nsec</span><span class="f">,</span> <span class="b">sec</span><span class="f">;</span>
<a name="54" /><span class="False">      54:</span> <span class="f">#</span> <span class="n">endif</span>
<a name="55" /><span class="False">      55:</span>     <span class="f">}</span> <span class="b">tv</span><span class="f">;</span>
<a name="56" /><span class="Maybe">      56:</span> <span class="f">#</span><span class="n">endif</span>
<a name="57" /><span class="Maybe">      57:</span> <span class="f">}</span><span class="f">;</span>
<a name="58" /><span class="Maybe">      58:</span> 
<a name="59" /><span class="Maybe">      59:</span> <span class="m">typedef</span> <span class="m">union</span> <span class="b">ktime</span> <span class="b">ktime_t</span><span class="f">;</span>        <span class="k">/* Kill this */</span>
<a name="60" /><span class="Maybe">      60:</span> 
<a name="61" /><span class="Maybe">      61:</span> <span class="k">/*</span>
<a name="62" /><span class="Maybe">      62:</span> <span class="k"> * ktime_t definitions when using the 64-bit scalar representation:</span>
<a name="63" /><span class="Maybe">      63:</span> <span class="k"> */</span>
<a name="64" /><span class="Maybe">      64:</span> 
<a name="65" /><span class="Maybe">      65:</span> <span class="f">#</span><span class="n">if</span> <span class="f">(</span><a href="cpu.c_macros_ref.html#_QklUU19QRVJfTE9OR18w"><span class="b">BITS_PER_LONG</span></a> <span class="f">==</span> <span class="c">64</span><span class="f">)</span> <span class="f">||</span> <span class="b">defined</span><span class="f">(</span><span class="b">CONFIG_KTIME_SCALAR</span><span class="f">)</span>
<a name="66" /><span class="Maybe">      66:</span> 
<a name="67" /><span class="Maybe">      67:</span> <span class="k">/**</span>
<a name="68" /><span class="Maybe">      68:</span> <span class="k"> * ktime_set - Set a ktime_t variable from a seconds/nanoseconds value</span>
<a name="69" /><span class="Maybe">      69:</span> <span class="k"> * @secs:    seconds to set</span>
<a name="70" /><span class="Maybe">      70:</span> <span class="k"> * @nsecs:    nanoseconds to set</span>
<a name="71" /><span class="Maybe">      71:</span> <span class="k"> *</span>
<a name="72" /><span class="Maybe">      72:</span> <span class="k"> * Return: The ktime_t representation of the value.</span>
<a name="73" /><span class="Maybe">      73:</span> <span class="k"> */</span>
<a name="74" /><span class="Maybe">      74:</span> <span class="m">static</span> <span class="m">inline</span> <span class="b">ktime_t</span> <span class="b">ktime_set</span><span class="f">(</span><span class="m">const</span> <span class="m">long</span> <span class="b">secs</span><span class="f">,</span> <span class="m">const</span> <span class="m">unsigned</span> <span class="m">long</span> <span class="b">nsecs</span><span class="f">)</span>
<a name="75" /><span class="Maybe">      75:</span> <span class="f">{</span>
<a name="76" /><span class="Maybe">      76:</span> <span class="f">#</span><span class="n">if</span> <span class="f">(</span><a href="cpu.c_macros_ref.html#_QklUU19QRVJfTE9OR18w"><span class="b">BITS_PER_LONG</span></a> <span class="f">==</span> <span class="c">64</span><span class="f">)</span>
<a name="77" /><span class="Maybe">      77:</span>     <span class="m">if</span> <span class="f">(</span><a href="cpu.c_macros_ref.html#_dW5saWtlbHlfMA__"><span class="b">unlikely</span></a><span class="f">(</span><span class="b">secs</span> <span class="f">&gt;=</span> <a href="cpu.c_macros_ref.html#_S1RJTUVfU0VDX01BWF8w"><span class="b">KTIME_SEC_MAX</span></a><span class="f">)</span><span class="f">)</span>
<a name="78" /><span class="Maybe">      78:</span>         <span class="m">return</span> <span class="f">(</span><span class="b">ktime_t</span><span class="f">)</span><span class="f">{</span> <span class="f">.</span><span class="b">tv64</span> <span class="f">=</span> <a href="cpu.c_macros_ref.html#_S1RJTUVfTUFYXzA_"><span class="b">KTIME_MAX</span></a> <span class="f">}</span><span class="f">;</span>
<a name="79" /><span class="Maybe">      79:</span> <span class="f">#</span><span class="n">endif</span>
<a name="80" /><span class="Maybe">      80:</span>     <span class="m">return</span> <span class="f">(</span><span class="b">ktime_t</span><span class="f">)</span> <span class="f">{</span> <span class="f">.</span><span class="b">tv64</span> <span class="f">=</span> <span class="f">(</span><span class="b">s64</span><span class="f">)</span><span class="b">secs</span> <span class="f">*</span> <a href="cpu.c_macros_ref.html#_TlNFQ19QRVJfU0VDXzA_"><span class="b">NSEC_PER_SEC</span></a> <span class="f">+</span> <span class="f">(</span><span class="b">s64</span><span class="f">)</span><span class="b">nsecs</span> <span class="f">}</span><span class="f">;</span>
<a name="81" /><span class="Maybe">      81:</span> <span class="f">}</span>
<a name="82" /><span class="Maybe">      82:</span> 
<a name="83" /><span class="Maybe">      83:</span> <span class="k">/* Subtract two ktime_t variables. rem = lhs -rhs: */</span>
<a name="84" /><span class="Maybe">      84:</span> <span class="f">#</span><span class="n">define</span> <a href="cpu.c_macros_ref.html#_a3RpbWVfc3ViXzA_"><span class="b">ktime_sub</span></a><span class="f">(</span><span class="b">lhs</span><span class="f">,</span> <span class="b">rhs</span><span class="f">)</span> \
<a name="85" /><span class="Maybe">      85:</span>         <span class="f">(</span><span class="f">{</span> <span class="f">(</span><span class="b">ktime_t</span><span class="f">)</span><span class="f">{</span> <span class="f">.</span><span class="b">tv64</span> <span class="f">=</span> <span class="f">(</span><span class="b">lhs</span><span class="f">)</span><span class="f">.</span><span class="b">tv64</span> <span class="f">-</span> <span class="f">(</span><span class="b">rhs</span><span class="f">)</span><span class="f">.</span><span class="b">tv64</span> <span class="f">}</span><span class="f">;</span> <span class="f">}</span><span class="f">)</span>
<a name="86" /><span class="Maybe">      86:</span> 
<a name="87" /><span class="Maybe">      87:</span> <span class="k">/* Add two ktime_t variables. res = lhs + rhs: */</span>
<a name="88" /><span class="Maybe">      88:</span> <span class="f">#</span><span class="n">define</span> <a href="cpu.c_macros_noref.html#_a3RpbWVfYWRkXzA_"><span class="b">ktime_add</span></a><span class="f">(</span><span class="b">lhs</span><span class="f">,</span> <span class="b">rhs</span><span class="f">)</span> \
<a name="89" /><span class="Maybe">      89:</span>         <span class="f">(</span><span class="f">{</span> <span class="f">(</span><span class="b">ktime_t</span><span class="f">)</span><span class="f">{</span> <span class="f">.</span><span class="b">tv64</span> <span class="f">=</span> <span class="f">(</span><span class="b">lhs</span><span class="f">)</span><span class="f">.</span><span class="b">tv64</span> <span class="f">+</span> <span class="f">(</span><span class="b">rhs</span><span class="f">)</span><span class="f">.</span><span class="b">tv64</span> <span class="f">}</span><span class="f">;</span> <span class="f">}</span><span class="f">)</span>
<a name="90" /><span class="Maybe">      90:</span> 
<a name="91" /><span class="Maybe">      91:</span> <span class="k">/*</span>
<a name="92" /><span class="Maybe">      92:</span> <span class="k"> * Add a ktime_t variable and a scalar nanosecond value.</span>
<a name="93" /><span class="Maybe">      93:</span> <span class="k"> * res = kt + nsval:</span>
<a name="94" /><span class="Maybe">      94:</span> <span class="k"> */</span>
<a name="95" /><span class="Maybe">      95:</span> <span class="f">#</span><span class="n">define</span> <a href="cpu.c_macros_ref.html#_a3RpbWVfYWRkX25zXzA_"><span class="b">ktime_add_ns</span></a><span class="f">(</span><span class="b">kt</span><span class="f">,</span> <span class="b">nsval</span><span class="f">)</span> \
<a name="96" /><span class="Maybe">      96:</span>         <span class="f">(</span><span class="f">{</span> <span class="f">(</span><span class="b">ktime_t</span><span class="f">)</span><span class="f">{</span> <span class="f">.</span><span class="b">tv64</span> <span class="f">=</span> <span class="f">(</span><span class="b">kt</span><span class="f">)</span><span class="f">.</span><span class="b">tv64</span> <span class="f">+</span> <span class="f">(</span><span class="b">nsval</span><span class="f">)</span> <span class="f">}</span><span class="f">;</span> <span class="f">}</span><span class="f">)</span>
<a name="97" /><span class="Maybe">      97:</span> 
<a name="98" /><span class="Maybe">      98:</span> <span class="k">/*</span>
<a name="99" /><span class="Maybe">      99:</span> <span class="k"> * Subtract a scalar nanosecod from a ktime_t variable</span>
<a name="100" /><span class="Maybe">     100:</span> <span class="k"> * res = kt - nsval:</span>
<a name="101" /><span class="Maybe">     101:</span> <span class="k"> */</span>
<a name="102" /><span class="Maybe">     102:</span> <span class="f">#</span><span class="n">define</span> <a href="cpu.c_macros_ref.html#_a3RpbWVfc3ViX25zXzA_"><span class="b">ktime_sub_ns</span></a><span class="f">(</span><span class="b">kt</span><span class="f">,</span> <span class="b">nsval</span><span class="f">)</span> \
<a name="103" /><span class="Maybe">     103:</span>         <span class="f">(</span><span class="f">{</span> <span class="f">(</span><span class="b">ktime_t</span><span class="f">)</span><span class="f">{</span> <span class="f">.</span><span class="b">tv64</span> <span class="f">=</span> <span class="f">(</span><span class="b">kt</span><span class="f">)</span><span class="f">.</span><span class="b">tv64</span> <span class="f">-</span> <span class="f">(</span><span class="b">nsval</span><span class="f">)</span> <span class="f">}</span><span class="f">;</span> <span class="f">}</span><span class="f">)</span>
<a name="104" /><span class="Maybe">     104:</span> 
<a name="105" /><span class="Maybe">     105:</span> <span class="k">/* convert a timespec to ktime_t format: */</span>
<a name="106" /><span class="Maybe">     106:</span> <span class="m">static</span> <span class="m">inline</span> <span class="b">ktime_t</span> <span class="b">timespec_to_ktime</span><span class="f">(</span><span class="m">struct</span> <span class="b">timespec</span> <span class="b">ts</span><span class="f">)</span>
<a name="107" /><span class="Maybe">     107:</span> <span class="f">{</span>
<a name="108" /><span class="Maybe">     108:</span>     <span class="m">return</span> <span class="b">ktime_set</span><span class="f">(</span><span class="b">ts</span><span class="f">.</span><span class="b">tv_sec</span><span class="f">,</span> <span class="b">ts</span><span class="f">.</span><span class="b">tv_nsec</span><span class="f">)</span><span class="f">;</span>
<a name="109" /><span class="Maybe">     109:</span> <span class="f">}</span>
<a name="110" /><span class="Maybe">     110:</span> 
<a name="111" /><span class="Maybe">     111:</span> <span class="k">/* convert a timeval to ktime_t format: */</span>
<a name="112" /><span class="Maybe">     112:</span> <span class="m">static</span> <span class="m">inline</span> <span class="b">ktime_t</span> <span class="b">timeval_to_ktime</span><span class="f">(</span><span class="m">struct</span> <span class="b">timeval</span> <span class="b">tv</span><span class="f">)</span>
<a name="113" /><span class="Maybe">     113:</span> <span class="f">{</span>
<a name="114" /><span class="Maybe">     114:</span>     <span class="m">return</span> <span class="b">ktime_set</span><span class="f">(</span><span class="b">tv</span><span class="f">.</span><span class="b">tv_sec</span><span class="f">,</span> <span class="b">tv</span><span class="f">.</span><span class="b">tv_usec</span> <span class="f">*</span> <a href="cpu.c_macros_ref.html#_TlNFQ19QRVJfVVNFQ18w"><span class="b">NSEC_PER_USEC</span></a><span class="f">)</span><span class="f">;</span>
<a name="115" /><span class="Maybe">     115:</span> <span class="f">}</span>
<a name="116" /><span class="Maybe">     116:</span> 
<a name="117" /><span class="Maybe">     117:</span> <span class="k">/* Map the ktime_t to timespec conversion to ns_to_timespec function */</span>
<a name="118" /><span class="Maybe">     118:</span> <span class="f">#</span><span class="n">define</span> <a href="cpu.c_macros_ref.html#_a3RpbWVfdG9fdGltZXNwZWNfMA__"><span class="b">ktime_to_timespec</span></a><span class="f">(</span><span class="b">kt</span><span class="f">)</span>        <span class="b">ns_to_timespec</span><span class="f">(</span><span class="f">(</span><span class="b">kt</span><span class="f">)</span><span class="f">.</span><span class="b">tv64</span><span class="f">)</span>
<a name="119" /><span class="Maybe">     119:</span> 
<a name="120" /><span class="Maybe">     120:</span> <span class="k">/* Map the ktime_t to timeval conversion to ns_to_timeval function */</span>
<a name="121" /><span class="Maybe">     121:</span> <span class="f">#</span><span class="n">define</span> <a href="cpu.c_macros_ref.html#_a3RpbWVfdG9fdGltZXZhbF8w"><span class="b">ktime_to_timeval</span></a><span class="f">(</span><span class="b">kt</span><span class="f">)</span>        <span class="b">ns_to_timeval</span><span class="f">(</span><span class="f">(</span><span class="b">kt</span><span class="f">)</span><span class="f">.</span><span class="b">tv64</span><span class="f">)</span>
<a name="122" /><span class="Maybe">     122:</span> 
<a name="123" /><span class="Maybe">     123:</span> <span class="k">/* Convert ktime_t to nanoseconds - NOP in the scalar storage format: */</span>
<a name="124" /><span class="Maybe">     124:</span> <span class="f">#</span><span class="n">define</span> <a href="cpu.c_macros_ref.html#_a3RpbWVfdG9fbnNfMA__"><span class="b">ktime_to_ns</span></a><span class="f">(</span><span class="b">kt</span><span class="f">)</span>            <span class="f">(</span><span class="f">(</span><span class="b">kt</span><span class="f">)</span><span class="f">.</span><span class="b">tv64</span><span class="f">)</span>
<a name="125" /><span class="Maybe">     125:</span> 
<a name="126" /><span class="False">     126:</span> <span class="f">#</span><span class="n">else</span>    <span class="k">/* !((BITS_PER_LONG == 64) || defined(CONFIG_KTIME_SCALAR)) */</span>
<a name="127" /><span class="False">     127:</span> 
<a name="128" /><span class="False">     128:</span> <span class="k">/*</span>
<a name="129" /><span class="False">     129:</span> <span class="k"> * Helper macros/inlines to get the ktime_t math right in the timespec</span>
<a name="130" /><span class="False">     130:</span> <span class="k"> * representation. The macros are sometimes ugly - their actual use is</span>
<a name="131" /><span class="False">     131:</span> <span class="k"> * pretty okay-ish, given the circumstances. We do all this for</span>
<a name="132" /><span class="False">     132:</span> <span class="k"> * performance reasons. The pure scalar nsec_t based code was nice and</span>
<a name="133" /><span class="False">     133:</span> <span class="k"> * simple, but created too many 64-bit / 32-bit conversions and divisions.</span>
<a name="134" /><span class="False">     134:</span> <span class="k"> *</span>
<a name="135" /><span class="False">     135:</span> <span class="k"> * Be especially aware that negative values are represented in a way</span>
<a name="136" /><span class="False">     136:</span> <span class="k"> * that the tv.sec field is negative and the tv.nsec field is greater</span>
<a name="137" /><span class="False">     137:</span> <span class="k"> * or equal to zero but less than nanoseconds per second. This is the</span>
<a name="138" /><span class="False">     138:</span> <span class="k"> * same representation which is used by timespecs.</span>
<a name="139" /><span class="False">     139:</span> <span class="k"> *</span>
<a name="140" /><span class="False">     140:</span> <span class="k"> *   tv.sec &lt; 0 and 0 &gt;= tv.nsec &lt; NSEC_PER_SEC</span>
<a name="141" /><span class="False">     141:</span> <span class="k"> */</span>
<a name="142" /><span class="False">     142:</span> 
<a name="143" /><span class="False">     143:</span> <span class="k">/* Set a ktime_t variable to a value in sec/nsec representation: */</span>
<a name="144" /><span class="False">     144:</span> <span class="m">static</span> <span class="m">inline</span> <span class="b">ktime_t</span> <span class="b">ktime_set</span><span class="f">(</span><span class="m">const</span> <span class="m">long</span> <span class="b">secs</span><span class="f">,</span> <span class="m">const</span> <span class="m">unsigned</span> <span class="m">long</span> <span class="b">nsecs</span><span class="f">)</span>
<a name="145" /><span class="False">     145:</span> <span class="f">{</span>
<a name="146" /><span class="False">     146:</span>     <span class="m">return</span> <span class="f">(</span><span class="b">ktime_t</span><span class="f">)</span> <span class="f">{</span> <span class="f">.</span><span class="b">tv</span> <span class="f">=</span> <span class="f">{</span> <span class="f">.</span><span class="b">sec</span> <span class="f">=</span> <span class="b">secs</span><span class="f">,</span> <span class="f">.</span><span class="b">nsec</span> <span class="f">=</span> <span class="b">nsecs</span> <span class="f">}</span> <span class="f">}</span><span class="f">;</span>
<a name="147" /><span class="False">     147:</span> <span class="f">}</span>
<a name="148" /><span class="False">     148:</span> 
<a name="149" /><span class="False">     149:</span> <span class="k">/**</span>
<a name="150" /><span class="False">     150:</span> <span class="k"> * ktime_sub - subtract two ktime_t variables</span>
<a name="151" /><span class="False">     151:</span> <span class="k"> * @lhs:    minuend</span>
<a name="152" /><span class="False">     152:</span> <span class="k"> * @rhs:    subtrahend</span>
<a name="153" /><span class="False">     153:</span> <span class="k"> *</span>
<a name="154" /><span class="False">     154:</span> <span class="k"> * Return: The remainder of the subtraction.</span>
<a name="155" /><span class="False">     155:</span> <span class="k"> */</span>
<a name="156" /><span class="False">     156:</span> <span class="m">static</span> <span class="m">inline</span> <span class="b">ktime_t</span> <a href="cpu.c_macros_ref.html#_a3RpbWVfc3ViXzA_"><span class="b">ktime_sub</span></a><span class="f">(</span><span class="m">const</span> <span class="b">ktime_t</span> <span class="b">lhs</span><span class="f">,</span> <span class="m">const</span> <span class="b">ktime_t</span> <span class="b">rhs</span><span class="f">)</span>
<a name="157" /><span class="False">     157:</span> <span class="f">{</span>
<a name="158" /><span class="False">     158:</span>     <span class="b">ktime_t</span> <span class="b">res</span><span class="f">;</span>
<a name="159" /><span class="False">     159:</span> 
<a name="160" /><span class="False">     160:</span>     <span class="b">res</span><span class="f">.</span><span class="b">tv64</span> <span class="f">=</span> <span class="b">lhs</span><span class="f">.</span><span class="b">tv64</span> <span class="f">-</span> <span class="b">rhs</span><span class="f">.</span><span class="b">tv64</span><span class="f">;</span>
<a name="161" /><span class="False">     161:</span>     <span class="m">if</span> <span class="f">(</span><span class="b">res</span><span class="f">.</span><span class="b">tv</span><span class="f">.</span><span class="b">nsec</span> <span class="f">&lt;</span> <span class="c">0</span><span class="f">)</span>
<a name="162" /><span class="False">     162:</span>         <span class="b">res</span><span class="f">.</span><span class="b">tv</span><span class="f">.</span><span class="b">nsec</span> <span class="f">+=</span> <a href="cpu.c_macros_ref.html#_TlNFQ19QRVJfU0VDXzA_"><span class="b">NSEC_PER_SEC</span></a><span class="f">;</span>
<a name="163" /><span class="False">     163:</span> 
<a name="164" /><span class="False">     164:</span>     <span class="m">return</span> <span class="b">res</span><span class="f">;</span>
<a name="165" /><span class="False">     165:</span> <span class="f">}</span>
<a name="166" /><span class="False">     166:</span> 
<a name="167" /><span class="False">     167:</span> <span class="k">/**</span>
<a name="168" /><span class="False">     168:</span> <span class="k"> * ktime_add - add two ktime_t variables</span>
<a name="169" /><span class="False">     169:</span> <span class="k"> * @add1:    addend1</span>
<a name="170" /><span class="False">     170:</span> <span class="k"> * @add2:    addend2</span>
<a name="171" /><span class="False">     171:</span> <span class="k"> *</span>
<a name="172" /><span class="False">     172:</span> <span class="k"> * Return: The sum of @add1 and @add2.</span>
<a name="173" /><span class="False">     173:</span> <span class="k"> */</span>
<a name="174" /><span class="False">     174:</span> <span class="m">static</span> <span class="m">inline</span> <span class="b">ktime_t</span> <a href="cpu.c_macros_noref.html#_a3RpbWVfYWRkXzA_"><span class="b">ktime_add</span></a><span class="f">(</span><span class="m">const</span> <span class="b">ktime_t</span> <span class="b">add1</span><span class="f">,</span> <span class="m">const</span> <span class="b">ktime_t</span> <span class="b">add2</span><span class="f">)</span>
<a name="175" /><span class="False">     175:</span> <span class="f">{</span>
<a name="176" /><span class="False">     176:</span>     <span class="b">ktime_t</span> <span class="b">res</span><span class="f">;</span>
<a name="177" /><span class="False">     177:</span> 
<a name="178" /><span class="False">     178:</span>     <span class="b">res</span><span class="f">.</span><span class="b">tv64</span> <span class="f">=</span> <span class="b">add1</span><span class="f">.</span><span class="b">tv64</span> <span class="f">+</span> <span class="b">add2</span><span class="f">.</span><span class="b">tv64</span><span class="f">;</span>
<a name="179" /><span class="False">     179:</span>     <span class="k">/*</span>
<a name="180" /><span class="False">     180:</span> <span class="k">     * performance trick: the (u32) -NSEC gives 0x00000000Fxxxxxxx</span>
<a name="181" /><span class="False">     181:</span> <span class="k">     * so we subtract NSEC_PER_SEC and add 1 to the upper 32 bit.</span>
<a name="182" /><span class="False">     182:</span> <span class="k">     *</span>
<a name="183" /><span class="False">     183:</span> <span class="k">     * it&apos;s equivalent to:</span>
<a name="184" /><span class="False">     184:</span> <span class="k">     *   tv.nsec -= NSEC_PER_SEC</span>
<a name="185" /><span class="False">     185:</span> <span class="k">     *   tv.sec ++;</span>
<a name="186" /><span class="False">     186:</span> <span class="k">     */</span>
<a name="187" /><span class="False">     187:</span>     <span class="m">if</span> <span class="f">(</span><span class="b">res</span><span class="f">.</span><span class="b">tv</span><span class="f">.</span><span class="b">nsec</span> <span class="f">&gt;=</span> <a href="cpu.c_macros_ref.html#_TlNFQ19QRVJfU0VDXzA_"><span class="b">NSEC_PER_SEC</span></a><span class="f">)</span>
<a name="188" /><span class="False">     188:</span>         <span class="b">res</span><span class="f">.</span><span class="b">tv64</span> <span class="f">+=</span> <span class="f">(</span><a href="cpu.c_macros_ref.html#_dTMyXzA_"><span class="b">u32</span></a><span class="f">)</span><span class="f">-</span><a href="cpu.c_macros_ref.html#_TlNFQ19QRVJfU0VDXzA_"><span class="b">NSEC_PER_SEC</span></a><span class="f">;</span>
<a name="189" /><span class="False">     189:</span> 
<a name="190" /><span class="False">     190:</span>     <span class="m">return</span> <span class="b">res</span><span class="f">;</span>
<a name="191" /><span class="False">     191:</span> <span class="f">}</span>
<a name="192" /><span class="False">     192:</span> 
<a name="193" /><span class="False">     193:</span> <span class="k">/**</span>
<a name="194" /><span class="False">     194:</span> <span class="k"> * ktime_add_ns - Add a scalar nanoseconds value to a ktime_t variable</span>
<a name="195" /><span class="False">     195:</span> <span class="k"> * @kt:        addend</span>
<a name="196" /><span class="False">     196:</span> <span class="k"> * @nsec:    the scalar nsec value to add</span>
<a name="197" /><span class="False">     197:</span> <span class="k"> *</span>
<a name="198" /><span class="False">     198:</span> <span class="k"> * Return: The sum of @kt and @nsec in ktime_t format.</span>
<a name="199" /><span class="False">     199:</span> <span class="k"> */</span>
<a name="200" /><span class="False">     200:</span> <span class="m">extern</span> <span class="b">ktime_t</span> <a href="cpu.c_macros_ref.html#_a3RpbWVfYWRkX25zXzA_"><span class="b">ktime_add_ns</span></a><span class="f">(</span><span class="m">const</span> <span class="b">ktime_t</span> <span class="b">kt</span><span class="f">,</span> <span class="b">u64</span> <span class="b">nsec</span><span class="f">)</span><span class="f">;</span>
<a name="201" /><span class="False">     201:</span> 
<a name="202" /><span class="False">     202:</span> <span class="k">/**</span>
<a name="203" /><span class="False">     203:</span> <span class="k"> * ktime_sub_ns - Subtract a scalar nanoseconds value from a ktime_t variable</span>
<a name="204" /><span class="False">     204:</span> <span class="k"> * @kt:        minuend</span>
<a name="205" /><span class="False">     205:</span> <span class="k"> * @nsec:    the scalar nsec value to subtract</span>
<a name="206" /><span class="False">     206:</span> <span class="k"> *</span>
<a name="207" /><span class="False">     207:</span> <span class="k"> * Return: The subtraction of @nsec from @kt in ktime_t format.</span>
<a name="208" /><span class="False">     208:</span> <span class="k"> */</span>
<a name="209" /><span class="False">     209:</span> <span class="m">extern</span> <span class="b">ktime_t</span> <a href="cpu.c_macros_ref.html#_a3RpbWVfc3ViX25zXzA_"><span class="b">ktime_sub_ns</span></a><span class="f">(</span><span class="m">const</span> <span class="b">ktime_t</span> <span class="b">kt</span><span class="f">,</span> <span class="b">u64</span> <span class="b">nsec</span><span class="f">)</span><span class="f">;</span>
<a name="210" /><span class="False">     210:</span> 
<a name="211" /><span class="False">     211:</span> <span class="k">/**</span>
<a name="212" /><span class="False">     212:</span> <span class="k"> * timespec_to_ktime - convert a timespec to ktime_t format</span>
<a name="213" /><span class="False">     213:</span> <span class="k"> * @ts:        the timespec variable to convert</span>
<a name="214" /><span class="False">     214:</span> <span class="k"> *</span>
<a name="215" /><span class="False">     215:</span> <span class="k"> * Return: A ktime_t variable with the converted timespec value.</span>
<a name="216" /><span class="False">     216:</span> <span class="k"> */</span>
<a name="217" /><span class="False">     217:</span> <span class="m">static</span> <span class="m">inline</span> <span class="b">ktime_t</span> <span class="b">timespec_to_ktime</span><span class="f">(</span><span class="m">const</span> <span class="m">struct</span> <span class="b">timespec</span> <span class="b">ts</span><span class="f">)</span>
<a name="218" /><span class="False">     218:</span> <span class="f">{</span>
<a name="219" /><span class="False">     219:</span>     <span class="m">return</span> <span class="f">(</span><span class="b">ktime_t</span><span class="f">)</span> <span class="f">{</span> <span class="f">.</span><span class="b">tv</span> <span class="f">=</span> <span class="f">{</span> <span class="f">.</span><span class="b">sec</span> <span class="f">=</span> <span class="f">(</span><span class="b">s32</span><span class="f">)</span><span class="b">ts</span><span class="f">.</span><span class="b">tv_sec</span><span class="f">,</span>
<a name="220" /><span class="False">     220:</span>                       <span class="f">.</span><span class="b">nsec</span> <span class="f">=</span> <span class="f">(</span><span class="b">s32</span><span class="f">)</span><span class="b">ts</span><span class="f">.</span><span class="b">tv_nsec</span> <span class="f">}</span> <span class="f">}</span><span class="f">;</span>
<a name="221" /><span class="False">     221:</span> <span class="f">}</span>
<a name="222" /><span class="False">     222:</span> 
<a name="223" /><span class="False">     223:</span> <span class="k">/**</span>
<a name="224" /><span class="False">     224:</span> <span class="k"> * timeval_to_ktime - convert a timeval to ktime_t format</span>
<a name="225" /><span class="False">     225:</span> <span class="k"> * @tv:        the timeval variable to convert</span>
<a name="226" /><span class="False">     226:</span> <span class="k"> *</span>
<a name="227" /><span class="False">     227:</span> <span class="k"> * Return: A ktime_t variable with the converted timeval value.</span>
<a name="228" /><span class="False">     228:</span> <span class="k"> */</span>
<a name="229" /><span class="False">     229:</span> <span class="m">static</span> <span class="m">inline</span> <span class="b">ktime_t</span> <span class="b">timeval_to_ktime</span><span class="f">(</span><span class="m">const</span> <span class="m">struct</span> <span class="b">timeval</span> <span class="b">tv</span><span class="f">)</span>
<a name="230" /><span class="False">     230:</span> <span class="f">{</span>
<a name="231" /><span class="False">     231:</span>     <span class="m">return</span> <span class="f">(</span><span class="b">ktime_t</span><span class="f">)</span> <span class="f">{</span> <span class="f">.</span><span class="b">tv</span> <span class="f">=</span> <span class="f">{</span> <span class="f">.</span><span class="b">sec</span> <span class="f">=</span> <span class="f">(</span><span class="b">s32</span><span class="f">)</span><span class="b">tv</span><span class="f">.</span><span class="b">tv_sec</span><span class="f">,</span>
<a name="232" /><span class="False">     232:</span>                    <span class="f">.</span><span class="b">nsec</span> <span class="f">=</span> <span class="f">(</span><span class="b">s32</span><span class="f">)</span><span class="f">(</span><span class="b">tv</span><span class="f">.</span><span class="b">tv_usec</span> <span class="f">*</span>
<a name="233" /><span class="False">     233:</span>                          <a href="cpu.c_macros_ref.html#_TlNFQ19QRVJfVVNFQ18w"><span class="b">NSEC_PER_USEC</span></a><span class="f">)</span> <span class="f">}</span> <span class="f">}</span><span class="f">;</span>
<a name="234" /><span class="False">     234:</span> <span class="f">}</span>
<a name="235" /><span class="False">     235:</span> 
<a name="236" /><span class="False">     236:</span> <span class="k">/**</span>
<a name="237" /><span class="False">     237:</span> <span class="k"> * ktime_to_timespec - convert a ktime_t variable to timespec format</span>
<a name="238" /><span class="False">     238:</span> <span class="k"> * @kt:        the ktime_t variable to convert</span>
<a name="239" /><span class="False">     239:</span> <span class="k"> *</span>
<a name="240" /><span class="False">     240:</span> <span class="k"> * Return: The timespec representation of the ktime value.</span>
<a name="241" /><span class="False">     241:</span> <span class="k"> */</span>
<a name="242" /><span class="False">     242:</span> <span class="m">static</span> <span class="m">inline</span> <span class="m">struct</span> <span class="b">timespec</span> <a href="cpu.c_macros_ref.html#_a3RpbWVfdG9fdGltZXNwZWNfMA__"><span class="b">ktime_to_timespec</span></a><span class="f">(</span><span class="m">const</span> <span class="b">ktime_t</span> <span class="b">kt</span><span class="f">)</span>
<a name="243" /><span class="False">     243:</span> <span class="f">{</span>
<a name="244" /><span class="False">     244:</span>     <span class="m">return</span> <span class="f">(</span><span class="m">struct</span> <span class="b">timespec</span><span class="f">)</span> <span class="f">{</span> <span class="f">.</span><span class="b">tv_sec</span> <span class="f">=</span> <span class="f">(</span><span class="b">time_t</span><span class="f">)</span> <span class="b">kt</span><span class="f">.</span><span class="b">tv</span><span class="f">.</span><span class="b">sec</span><span class="f">,</span>
<a name="245" /><span class="False">     245:</span>                    <span class="f">.</span><span class="b">tv_nsec</span> <span class="f">=</span> <span class="f">(</span><span class="m">long</span><span class="f">)</span> <span class="b">kt</span><span class="f">.</span><span class="b">tv</span><span class="f">.</span><span class="b">nsec</span> <span class="f">}</span><span class="f">;</span>
<a name="246" /><span class="False">     246:</span> <span class="f">}</span>
<a name="247" /><span class="False">     247:</span> 
<a name="248" /><span class="False">     248:</span> <span class="k">/**</span>
<a name="249" /><span class="False">     249:</span> <span class="k"> * ktime_to_timeval - convert a ktime_t variable to timeval format</span>
<a name="250" /><span class="False">     250:</span> <span class="k"> * @kt:        the ktime_t variable to convert</span>
<a name="251" /><span class="False">     251:</span> <span class="k"> *</span>
<a name="252" /><span class="False">     252:</span> <span class="k"> * Return: The timeval representation of the ktime value.</span>
<a name="253" /><span class="False">     253:</span> <span class="k"> */</span>
<a name="254" /><span class="False">     254:</span> <span class="m">static</span> <span class="m">inline</span> <span class="m">struct</span> <span class="b">timeval</span> <a href="cpu.c_macros_ref.html#_a3RpbWVfdG9fdGltZXZhbF8w"><span class="b">ktime_to_timeval</span></a><span class="f">(</span><span class="m">const</span> <span class="b">ktime_t</span> <span class="b">kt</span><span class="f">)</span>
<a name="255" /><span class="False">     255:</span> <span class="f">{</span>
<a name="256" /><span class="False">     256:</span>     <span class="m">return</span> <span class="f">(</span><span class="m">struct</span> <span class="b">timeval</span><span class="f">)</span> <span class="f">{</span>
<a name="257" /><span class="False">     257:</span>         <span class="f">.</span><span class="b">tv_sec</span> <span class="f">=</span> <span class="f">(</span><span class="b">time_t</span><span class="f">)</span> <span class="b">kt</span><span class="f">.</span><span class="b">tv</span><span class="f">.</span><span class="b">sec</span><span class="f">,</span>
<a name="258" /><span class="False">     258:</span>         <span class="f">.</span><span class="b">tv_usec</span> <span class="f">=</span> <span class="f">(</span><span class="b">suseconds_t</span><span class="f">)</span> <span class="f">(</span><span class="b">kt</span><span class="f">.</span><span class="b">tv</span><span class="f">.</span><span class="b">nsec</span> <span class="f">/</span> <a href="cpu.c_macros_ref.html#_TlNFQ19QRVJfVVNFQ18w"><span class="b">NSEC_PER_USEC</span></a><span class="f">)</span> <span class="f">}</span><span class="f">;</span>
<a name="259" /><span class="False">     259:</span> <span class="f">}</span>
<a name="260" /><span class="False">     260:</span> 
<a name="261" /><span class="False">     261:</span> <span class="k">/**</span>
<a name="262" /><span class="False">     262:</span> <span class="k"> * ktime_to_ns - convert a ktime_t variable to scalar nanoseconds</span>
<a name="263" /><span class="False">     263:</span> <span class="k"> * @kt:        the ktime_t variable to convert</span>
<a name="264" /><span class="False">     264:</span> <span class="k"> *</span>
<a name="265" /><span class="False">     265:</span> <span class="k"> * Return: The scalar nanoseconds representation of @kt.</span>
<a name="266" /><span class="False">     266:</span> <span class="k"> */</span>
<a name="267" /><span class="False">     267:</span> <span class="m">static</span> <span class="m">inline</span> <span class="b">s64</span> <a href="cpu.c_macros_ref.html#_a3RpbWVfdG9fbnNfMA__"><span class="b">ktime_to_ns</span></a><span class="f">(</span><span class="m">const</span> <span class="b">ktime_t</span> <span class="b">kt</span><span class="f">)</span>
<a name="268" /><span class="False">     268:</span> <span class="f">{</span>
<a name="269" /><span class="False">     269:</span>     <span class="m">return</span> <span class="f">(</span><span class="b">s64</span><span class="f">)</span> <span class="b">kt</span><span class="f">.</span><span class="b">tv</span><span class="f">.</span><span class="b">sec</span> <span class="f">*</span> <a href="cpu.c_macros_ref.html#_TlNFQ19QRVJfU0VDXzA_"><span class="b">NSEC_PER_SEC</span></a> <span class="f">+</span> <span class="b">kt</span><span class="f">.</span><span class="b">tv</span><span class="f">.</span><span class="b">nsec</span><span class="f">;</span>
<a name="270" /><span class="False">     270:</span> <span class="f">}</span>
<a name="271" /><span class="False">     271:</span> 
<a name="272" /><span class="Maybe">     272:</span> <span class="f">#</span><span class="n">endif</span>    <span class="k">/* !((BITS_PER_LONG == 64) || defined(CONFIG_KTIME_SCALAR)) */</span>
<a name="273" /><span class="Maybe">     273:</span> 
<a name="274" /><span class="Maybe">     274:</span> <span class="k">/**</span>
<a name="275" /><span class="Maybe">     275:</span> <span class="k"> * ktime_equal - Compares two ktime_t variables to see if they are equal</span>
<a name="276" /><span class="Maybe">     276:</span> <span class="k"> * @cmp1:    comparable1</span>
<a name="277" /><span class="Maybe">     277:</span> <span class="k"> * @cmp2:    comparable2</span>
<a name="278" /><span class="Maybe">     278:</span> <span class="k"> *</span>
<a name="279" /><span class="Maybe">     279:</span> <span class="k"> * Compare two ktime_t variables.</span>
<a name="280" /><span class="Maybe">     280:</span> <span class="k"> *</span>
<a name="281" /><span class="Maybe">     281:</span> <span class="k"> * Return: 1 if equal.</span>
<a name="282" /><span class="Maybe">     282:</span> <span class="k"> */</span>
<a name="283" /><span class="Maybe">     283:</span> <span class="m">static</span> <span class="m">inline</span> <span class="m">int</span> <span class="b">ktime_equal</span><span class="f">(</span><span class="m">const</span> <span class="b">ktime_t</span> <span class="b">cmp1</span><span class="f">,</span> <span class="m">const</span> <span class="b">ktime_t</span> <span class="b">cmp2</span><span class="f">)</span>
<a name="284" /><span class="Maybe">     284:</span> <span class="f">{</span>
<a name="285" /><span class="Maybe">     285:</span>     <span class="m">return</span> <span class="b">cmp1</span><span class="f">.</span><span class="b">tv64</span> <span class="f">==</span> <span class="b">cmp2</span><span class="f">.</span><span class="b">tv64</span><span class="f">;</span>
<a name="286" /><span class="Maybe">     286:</span> <span class="f">}</span>
<a name="287" /><span class="Maybe">     287:</span> 
<a name="288" /><span class="Maybe">     288:</span> <span class="k">/**</span>
<a name="289" /><span class="Maybe">     289:</span> <span class="k"> * ktime_compare - Compares two ktime_t variables for less, greater or equal</span>
<a name="290" /><span class="Maybe">     290:</span> <span class="k"> * @cmp1:    comparable1</span>
<a name="291" /><span class="Maybe">     291:</span> <span class="k"> * @cmp2:    comparable2</span>
<a name="292" /><span class="Maybe">     292:</span> <span class="k"> *</span>
<a name="293" /><span class="Maybe">     293:</span> <span class="k"> * Return: ...</span>
<a name="294" /><span class="Maybe">     294:</span> <span class="k"> *   cmp1  &lt; cmp2: return &lt;0</span>
<a name="295" /><span class="Maybe">     295:</span> <span class="k"> *   cmp1 == cmp2: return 0</span>
<a name="296" /><span class="Maybe">     296:</span> <span class="k"> *   cmp1  &gt; cmp2: return &gt;0</span>
<a name="297" /><span class="Maybe">     297:</span> <span class="k"> */</span>
<a name="298" /><span class="Maybe">     298:</span> <span class="m">static</span> <span class="m">inline</span> <span class="m">int</span> <span class="b">ktime_compare</span><span class="f">(</span><span class="m">const</span> <span class="b">ktime_t</span> <span class="b">cmp1</span><span class="f">,</span> <span class="m">const</span> <span class="b">ktime_t</span> <span class="b">cmp2</span><span class="f">)</span>
<a name="299" /><span class="Maybe">     299:</span> <span class="f">{</span>
<a name="300" /><span class="Maybe">     300:</span>     <span class="m">if</span> <span class="f">(</span><span class="b">cmp1</span><span class="f">.</span><span class="b">tv64</span> <span class="f">&lt;</span> <span class="b">cmp2</span><span class="f">.</span><span class="b">tv64</span><span class="f">)</span>
<a name="301" /><span class="Maybe">     301:</span>         <span class="m">return</span> <span class="f">-</span><span class="c">1</span><span class="f">;</span>
<a name="302" /><span class="Maybe">     302:</span>     <span class="m">if</span> <span class="f">(</span><span class="b">cmp1</span><span class="f">.</span><span class="b">tv64</span> <span class="f">&gt;</span> <span class="b">cmp2</span><span class="f">.</span><span class="b">tv64</span><span class="f">)</span>
<a name="303" /><span class="Maybe">     303:</span>         <span class="m">return</span> <span class="c">1</span><span class="f">;</span>
<a name="304" /><span class="Maybe">     304:</span>     <span class="m">return</span> <span class="c">0</span><span class="f">;</span>
<a name="305" /><span class="Maybe">     305:</span> <span class="f">}</span>
<a name="306" /><span class="Maybe">     306:</span> 
<a name="307" /><span class="Maybe">     307:</span> <span class="m">static</span> <span class="m">inline</span> <span class="b">s64</span> <span class="b">ktime_to_us</span><span class="f">(</span><span class="m">const</span> <span class="b">ktime_t</span> <span class="b">kt</span><span class="f">)</span>
<a name="308" /><span class="Maybe">     308:</span> <span class="f">{</span>
<a name="309" /><span class="Maybe">     309:</span>     <span class="m">struct</span> <span class="b">timeval</span> <span class="b">tv</span> <span class="f">=</span> <a href="cpu.c_macros_ref.html#_a3RpbWVfdG9fdGltZXZhbF8w"><span class="b">ktime_to_timeval</span></a><span class="f">(</span><span class="b">kt</span><span class="f">)</span><span class="f">;</span>
<a name="310" /><span class="Maybe">     310:</span>     <span class="m">return</span> <span class="f">(</span><span class="b">s64</span><span class="f">)</span> <span class="b">tv</span><span class="f">.</span><span class="b">tv_sec</span> <span class="f">*</span> <a href="cpu.c_macros_ref.html#_VVNFQ19QRVJfU0VDXzA_"><span class="b">USEC_PER_SEC</span></a> <span class="f">+</span> <span class="b">tv</span><span class="f">.</span><span class="b">tv_usec</span><span class="f">;</span>
<a name="311" /><span class="Maybe">     311:</span> <span class="f">}</span>
<a name="312" /><span class="Maybe">     312:</span> 
<a name="313" /><span class="Maybe">     313:</span> <span class="m">static</span> <span class="m">inline</span> <span class="b">s64</span> <span class="b">ktime_to_ms</span><span class="f">(</span><span class="m">const</span> <span class="b">ktime_t</span> <span class="b">kt</span><span class="f">)</span>
<a name="314" /><span class="Maybe">     314:</span> <span class="f">{</span>
<a name="315" /><span class="Maybe">     315:</span>     <span class="m">struct</span> <span class="b">timeval</span> <span class="b">tv</span> <span class="f">=</span> <a href="cpu.c_macros_ref.html#_a3RpbWVfdG9fdGltZXZhbF8w"><span class="b">ktime_to_timeval</span></a><span class="f">(</span><span class="b">kt</span><span class="f">)</span><span class="f">;</span>
<a name="316" /><span class="Maybe">     316:</span>     <span class="m">return</span> <span class="f">(</span><span class="b">s64</span><span class="f">)</span> <span class="b">tv</span><span class="f">.</span><span class="b">tv_sec</span> <span class="f">*</span> <a href="cpu.c_macros_ref.html#_TVNFQ19QRVJfU0VDXzA_"><span class="b">MSEC_PER_SEC</span></a> <span class="f">+</span> <span class="b">tv</span><span class="f">.</span><span class="b">tv_usec</span> <span class="f">/</span> <a href="cpu.c_macros_ref.html#_VVNFQ19QRVJfTVNFQ18w"><span class="b">USEC_PER_MSEC</span></a><span class="f">;</span>
<a name="317" /><span class="Maybe">     317:</span> <span class="f">}</span>
<a name="318" /><span class="Maybe">     318:</span> 
<a name="319" /><span class="Maybe">     319:</span> <span class="m">static</span> <span class="m">inline</span> <span class="b">s64</span> <span class="b">ktime_us_delta</span><span class="f">(</span><span class="m">const</span> <span class="b">ktime_t</span> <span class="b">later</span><span class="f">,</span> <span class="m">const</span> <span class="b">ktime_t</span> <span class="b">earlier</span><span class="f">)</span>
<a name="320" /><span class="Maybe">     320:</span> <span class="f">{</span>
<a name="321" /><span class="Maybe">     321:</span>        <span class="m">return</span> <span class="b">ktime_to_us</span><span class="f">(</span><a href="cpu.c_macros_ref.html#_a3RpbWVfc3ViXzA_"><span class="b">ktime_sub</span></a><span class="f">(</span><span class="b">later</span><span class="f">,</span> <span class="b">earlier</span><span class="f">)</span><span class="f">)</span><span class="f">;</span>
<a name="322" /><span class="Maybe">     322:</span> <span class="f">}</span>
<a name="323" /><span class="Maybe">     323:</span> 
<a name="324" /><span class="Maybe">     324:</span> <span class="m">static</span> <span class="m">inline</span> <span class="b">ktime_t</span> <span class="b">ktime_add_us</span><span class="f">(</span><span class="m">const</span> <span class="b">ktime_t</span> <span class="b">kt</span><span class="f">,</span> <span class="m">const</span> <span class="b">u64</span> <span class="b">usec</span><span class="f">)</span>
<a name="325" /><span class="Maybe">     325:</span> <span class="f">{</span>
<a name="326" /><span class="Maybe">     326:</span>     <span class="m">return</span> <a href="cpu.c_macros_ref.html#_a3RpbWVfYWRkX25zXzA_"><span class="b">ktime_add_ns</span></a><span class="f">(</span><span class="b">kt</span><span class="f">,</span> <span class="b">usec</span> <span class="f">*</span> <a href="cpu.c_macros_ref.html#_TlNFQ19QRVJfVVNFQ18w"><span class="b">NSEC_PER_USEC</span></a><span class="f">)</span><span class="f">;</span>
<a name="327" /><span class="Maybe">     327:</span> <span class="f">}</span>
<a name="328" /><span class="Maybe">     328:</span> 
<a name="329" /><span class="Maybe">     329:</span> <span class="m">static</span> <span class="m">inline</span> <span class="b">ktime_t</span> <span class="b">ktime_add_ms</span><span class="f">(</span><span class="m">const</span> <span class="b">ktime_t</span> <span class="b">kt</span><span class="f">,</span> <span class="m">const</span> <span class="b">u64</span> <span class="b">msec</span><span class="f">)</span>
<a name="330" /><span class="Maybe">     330:</span> <span class="f">{</span>
<a name="331" /><span class="Maybe">     331:</span>     <span class="m">return</span> <a href="cpu.c_macros_ref.html#_a3RpbWVfYWRkX25zXzA_"><span class="b">ktime_add_ns</span></a><span class="f">(</span><span class="b">kt</span><span class="f">,</span> <span class="b">msec</span> <span class="f">*</span> <a href="cpu.c_macros_ref.html#_TlNFQ19QRVJfTVNFQ18w"><span class="b">NSEC_PER_MSEC</span></a><span class="f">)</span><span class="f">;</span>
<a name="332" /><span class="Maybe">     332:</span> <span class="f">}</span>
<a name="333" /><span class="Maybe">     333:</span> 
<a name="334" /><span class="Maybe">     334:</span> <span class="m">static</span> <span class="m">inline</span> <span class="b">ktime_t</span> <span class="b">ktime_sub_us</span><span class="f">(</span><span class="m">const</span> <span class="b">ktime_t</span> <span class="b">kt</span><span class="f">,</span> <span class="m">const</span> <span class="b">u64</span> <span class="b">usec</span><span class="f">)</span>
<a name="335" /><span class="Maybe">     335:</span> <span class="f">{</span>
<a name="336" /><span class="Maybe">     336:</span>     <span class="m">return</span> <a href="cpu.c_macros_ref.html#_a3RpbWVfc3ViX25zXzA_"><span class="b">ktime_sub_ns</span></a><span class="f">(</span><span class="b">kt</span><span class="f">,</span> <span class="b">usec</span> <span class="f">*</span> <a href="cpu.c_macros_ref.html#_TlNFQ19QRVJfVVNFQ18w"><span class="b">NSEC_PER_USEC</span></a><span class="f">)</span><span class="f">;</span>
<a name="337" /><span class="Maybe">     337:</span> <span class="f">}</span>
<a name="338" /><span class="Maybe">     338:</span> 
<a name="339" /><span class="Maybe">     339:</span> <span class="m">extern</span> <span class="b">ktime_t</span> <span class="b">ktime_add_safe</span><span class="f">(</span><span class="m">const</span> <span class="b">ktime_t</span> <span class="b">lhs</span><span class="f">,</span> <span class="m">const</span> <span class="b">ktime_t</span> <span class="b">rhs</span><span class="f">)</span><span class="f">;</span>
<a name="340" /><span class="Maybe">     340:</span> 
<a name="341" /><span class="Maybe">     341:</span> <span class="k">/**</span>
<a name="342" /><span class="Maybe">     342:</span> <span class="k"> * ktime_to_timespec_cond - convert a ktime_t variable to timespec</span>
<a name="343" /><span class="Maybe">     343:</span> <span class="k"> *                format only if the variable contains data</span>
<a name="344" /><span class="Maybe">     344:</span> <span class="k"> * @kt:        the ktime_t variable to convert</span>
<a name="345" /><span class="Maybe">     345:</span> <span class="k"> * @ts:        the timespec variable to store the result in</span>
<a name="346" /><span class="Maybe">     346:</span> <span class="k"> *</span>
<a name="347" /><span class="Maybe">     347:</span> <span class="k"> * Return: %true if there was a successful conversion, %false if kt was 0.</span>
<a name="348" /><span class="Maybe">     348:</span> <span class="k"> */</span>
<a name="349" /><span class="Maybe">     349:</span> <span class="m">static</span> <span class="m">inline</span> <a href="cpu.c_macros_ref.html#_X19tdXN0X2NoZWNrXzE_"><span class="b">__must_check</span></a> <span class="m">bool</span> <span class="b">ktime_to_timespec_cond</span><span class="f">(</span><span class="m">const</span> <span class="b">ktime_t</span> <span class="b">kt</span><span class="f">,</span>
<a name="350" /><span class="Maybe">     350:</span>                                <span class="m">struct</span> <span class="b">timespec</span> <span class="f">*</span><span class="b">ts</span><span class="f">)</span>
<a name="351" /><span class="Maybe">     351:</span> <span class="f">{</span>
<a name="352" /><span class="Maybe">     352:</span>     <span class="m">if</span> <span class="f">(</span><span class="b">kt</span><span class="f">.</span><span class="b">tv64</span><span class="f">)</span> <span class="f">{</span>
<a name="353" /><span class="Maybe">     353:</span>         <span class="f">*</span><span class="b">ts</span> <span class="f">=</span> <a href="cpu.c_macros_ref.html#_a3RpbWVfdG9fdGltZXNwZWNfMA__"><span class="b">ktime_to_timespec</span></a><span class="f">(</span><span class="b">kt</span><span class="f">)</span><span class="f">;</span>
<a name="354" /><span class="Maybe">     354:</span>         <span class="m">return</span> <span class="m">true</span><span class="f">;</span>
<a name="355" /><span class="Maybe">     355:</span>     <span class="f">}</span> <span class="m">else</span> <span class="f">{</span>
<a name="356" /><span class="Maybe">     356:</span>         <span class="m">return</span> <span class="m">false</span><span class="f">;</span>
<a name="357" /><span class="Maybe">     357:</span>     <span class="f">}</span>
<a name="358" /><span class="Maybe">     358:</span> <span class="f">}</span>
<a name="359" /><span class="Maybe">     359:</span> 
<a name="360" /><span class="Maybe">     360:</span> <span class="k">/*</span>
<a name="361" /><span class="Maybe">     361:</span> <span class="k"> * The resolution of the clocks. The resolution value is returned in</span>
<a name="362" /><span class="Maybe">     362:</span> <span class="k"> * the clock_getres() system call to give application programmers an</span>
<a name="363" /><span class="Maybe">     363:</span> <span class="k"> * idea of the (in)accuracy of timers. Timer values are rounded up to</span>
<a name="364" /><span class="Maybe">     364:</span> <span class="k"> * this resolution values.</span>
<a name="365" /><span class="Maybe">     365:</span> <span class="k"> */</span>
<a name="366" /><span class="Maybe">     366:</span> <span class="f">#</span><span class="n">define</span> <a href="cpu.c_macros_noref.html#_TE9XX1JFU19OU0VDXzA_"><span class="b">LOW_RES_NSEC</span></a>        <a href="cpu.c_macros_ref.html#_VElDS19OU0VDXzA_"><span class="b">TICK_NSEC</span></a>
<a name="367" /><span class="Maybe">     367:</span> <span class="f">#</span><span class="n">define</span> <a href="cpu.c_macros_noref.html#_S1RJTUVfTE9XX1JFU18w"><span class="b">KTIME_LOW_RES</span></a>        <span class="f">(</span><span class="b">ktime_t</span><span class="f">)</span><span class="f">{</span> <span class="f">.</span><span class="b">tv64</span> <span class="f">=</span> <a href="cpu.c_macros_noref.html#_TE9XX1JFU19OU0VDXzA_"><span class="b">LOW_RES_NSEC</span></a> <span class="f">}</span>
<a name="368" /><span class="Maybe">     368:</span> 
<a name="369" /><span class="Maybe">     369:</span> <span class="k">/* Get the monotonic time in timespec format: */</span>
<a name="370" /><span class="Maybe">     370:</span> <span class="m">extern</span> <span class="m">void</span> <span class="b">ktime_get_ts</span><span class="f">(</span><span class="m">struct</span> <span class="b">timespec</span> <span class="f">*</span><span class="b">ts</span><span class="f">)</span><span class="f">;</span>
<a name="371" /><span class="Maybe">     371:</span> 
<a name="372" /><span class="Maybe">     372:</span> <span class="k">/* Get the real (wall-) time in timespec format: */</span>
<a name="373" /><span class="Maybe">     373:</span> <span class="f">#</span><span class="n">define</span> <a href="cpu.c_macros_noref.html#_a3RpbWVfZ2V0X3JlYWxfdHNfMA__"><span class="b">ktime_get_real_ts</span></a><span class="f">(</span><span class="b">ts</span><span class="f">)</span>    <span class="b">getnstimeofday</span><span class="f">(</span><span class="b">ts</span><span class="f">)</span>
<a name="374" /><span class="Maybe">     374:</span> 
<a name="375" /><span class="Maybe">     375:</span> <span class="m">static</span> <span class="m">inline</span> <span class="b">ktime_t</span> <span class="b">ns_to_ktime</span><span class="f">(</span><span class="b">u64</span> <span class="b">ns</span><span class="f">)</span>
<a name="376" /><span class="Maybe">     376:</span> <span class="f">{</span>
<a name="377" /><span class="Maybe">     377:</span>     <span class="m">static</span> <span class="m">const</span> <span class="b">ktime_t</span> <span class="b">ktime_zero</span> <span class="f">=</span> <span class="f">{</span> <span class="f">.</span><span class="b">tv64</span> <span class="f">=</span> <span class="c">0</span> <span class="f">}</span><span class="f">;</span>
<a name="378" /><span class="Maybe">     378:</span> 
<a name="379" /><span class="Maybe">     379:</span>     <span class="m">return</span> <a href="cpu.c_macros_ref.html#_a3RpbWVfYWRkX25zXzA_"><span class="b">ktime_add_ns</span></a><span class="f">(</span><span class="b">ktime_zero</span><span class="f">,</span> <span class="b">ns</span><span class="f">)</span><span class="f">;</span>
<a name="380" /><span class="Maybe">     380:</span> <span class="f">}</span>
<a name="381" /><span class="Maybe">     381:</span> 
<a name="382" /><span class="Maybe">     382:</span> <span class="m">static</span> <span class="m">inline</span> <span class="b">ktime_t</span> <span class="b">ms_to_ktime</span><span class="f">(</span><span class="b">u64</span> <span class="b">ms</span><span class="f">)</span>
<a name="383" /><span class="Maybe">     383:</span> <span class="f">{</span>
<a name="384" /><span class="Maybe">     384:</span>     <span class="m">static</span> <span class="m">const</span> <span class="b">ktime_t</span> <span class="b">ktime_zero</span> <span class="f">=</span> <span class="f">{</span> <span class="f">.</span><span class="b">tv64</span> <span class="f">=</span> <span class="c">0</span> <span class="f">}</span><span class="f">;</span>
<a name="385" /><span class="Maybe">     385:</span> 
<a name="386" /><span class="Maybe">     386:</span>     <span class="m">return</span> <span class="b">ktime_add_ms</span><span class="f">(</span><span class="b">ktime_zero</span><span class="f">,</span> <span class="b">ms</span><span class="f">)</span><span class="f">;</span>
<a name="387" /><span class="Maybe">     387:</span> <span class="f">}</span>
<a name="388" /><span class="Maybe">     388:</span> 
<a name="389" /><span class="True">     389:</span> <span class="f">#</span><span class="n">endif</span>
<a name="390" /><span class="True">     390:</span> </pre>
  </body>
</html>
